package org.example.likou150.array;

/*
* https://leetcode.cn/problems/valid-palindrome/?envType=study-plan-v2&envId=top-interview-150
* */
public class IsPalindrome {
    public static void main(String[] args) {
        String s = "race a car";
        IsPalindrome isPalindrome=new IsPalindrome();
        boolean palindrome = isPalindrome.isPalindrome(s);
        System.out.println(palindrome);
    }

    public boolean isPalindrome(String s) {
        char[] sCharArray = s.toCharArray();
        int left = 0;
        int right = s.length()-1;
        while (left<=right) {
            while(left<=right && !Character.isLetterOrDigit(sCharArray[left])){
                left++;
            }
            while(left<=right && !Character.isLetterOrDigit(sCharArray[right])){
                right--;
            }
            String s1 = String.valueOf(sCharArray[left]);
            String s2 = String.valueOf(sCharArray[right]);
//            if (!String.valueOf(sCharArray[left++]).equalsIgnoreCase(String.valueOf(sCharArray[right--]))) {
            if (Character.toLowerCase(sCharArray[left])!=Character.toLowerCase(sCharArray[right])) {
                return false;
            }
        }
        return true;
    }
}
